﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PatternMemento
{
    class Program
    {
        static void Main(string[] args)
        {

            Document document = new Document();
            History history = new History();

            document.Changer("input 1"); history.Add(document.Save()); 
            document.Changer("input 2"); history.Add(document.Save());
            document.Changer("input 3"); history.Add(document.Save());

            document.Resume(history.GetLastContext());
            document.Print();
             
            document.Resume(history.GetLastContext());
            document.Print();


            Console.ReadKey();
             
        }
    }

    class Document
    {
        string context = string.Empty;

        public Backup Save( )
        {
            return new Backup(context);
        }

        public void Resume(Backup _backup)
        {
            context = _backup.context; 
        }

        public void Changer(string _context)
        {
            this.context = _context;
        }

        public void Print()
        {
            Console.WriteLine(context);
        
        }
         
    }
     


    interface IMemento
    { 
    
    }


    class Backup : IMemento
    {
        public string context;
        public Backup(string str )
        {
            context = str; 
        }
      
    }
     
    class History
    {
        Stack<Backup> backups = new Stack<Backup>();
        public void Add(Backup backup)
        {
            backups.Push(backup);
        }

        public Backup GetLastContext()
        {
            return backups.Pop();
        }
    }

}
